<?php

namespace App\Modules\Admin\Http\Controllers;

use App\Http\Controllers\BaseController;
use App\Services\VolunteerActivityService;
use Illuminate\Http\Request;

class VolunteerActivityController extends BaseController
{
    public function __construct(VolunteerActivityService $volunteerActivityService)
    {
        $this->middleware('check.adminLogin')->except('index');

        $this->volunteerActivityService = $volunteerActivityService;
    }

    public function index()
    {
        $param = [];
        $data = $this->volunteerActivityService->getList($param);

        return $this->response->success($data);
    }

    public function show(Request $request)
    {
        $id = $request->input('id');
        $result = $this->volunteerActivityService->getInfo($id);

        return $this->response->success($result);
    }

    public function store(Request $request)
    {
        $param = $this->validationParameter([
            'title|标题' => 'require',
            'content|内容' => 'require',
            'image|封面图' => 'require',
            'sign_up_start|开始报名时间' => 'require',
            'sign_up_end|结束报名时间' => 'require',
            'activity_time_start|开始活动时间' => 'require',
            'activity_time_end|结束活动时间' => 'require',
            'limit_count|报名人数限制' => 'require',
            'post_count|岗位数' => 'require',
            'service_object|服务对象' => 'require',
            'volunteer_support|志愿者保障' => 'require',
            'service_time|服务时间' => 'require',
        ]);

        $param['publisher_uid'] = $request->user()->admin_uid ?? null;

        $result = $this->volunteerActivityService->add($param);

        return $this->response->success($result);
    }

    public function update(Request $request)
    {
        $id = $request->input('id');
        $param = [];
        $result = $this->volunteerActivityService->update($param, $id);

        return $this->response->success($result);
    }

    public function destroy(Request $request)
    {
        $id = $request->input('id');
        $result = $this->volunteerActivityService->delete($id);

        return $this->response->success($result);
    }
}
